package base.day06;

import java.util.Random;
import java.util.Scanner;


public class Study3 {
    public static void main(String[] args) {
        //猜数字
        Random rd = new Random();
        int number = rd.nextInt(100);
        int count = 1;
        while (true) {
            Scanner sc = new Scanner(System.in);
            System.out.println("请输入猜测的数字：");
            int guess_number = sc.nextInt();
            if (guess_number == number) {
                System.out.println("猜对了");
                break;
            } else {
                if (guess_number > number) {
                    System.out.println("猜测数字太大，再试一次");
                } else {
                    System.out.println("猜测数字太小，再试一次");
                }
            }
            count += 1;
        }
        System.out.println("一共猜测了" + count + "次");
    }
}
